<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-09-22 10:26:19
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-09-24 13:06:25
 * @Description: 
 * 
-->
<template>
  <el-dialog
    draggable
    overflow
    v-model="visible"
    :title="'入账'"
    :width="800"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form :model="form" :rules="rules" ref="dialogForm" label-width="70px">
      <sk-tabs type="border-card" @tab-change="tabChange">
        <el-tab-pane label="入账信息">
          <el-row :gutter="40">
            <el-col :span="10">
              <el-form-item label="汇票编号" prop="code">
                <el-input v-model="form.code" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="出票日期" prop="draftdate">
                <el-date-picker
                  v-model="form.draftdate"
                  type="date"
                  placeholder="选择日期"
                  format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="到期日期" prop="duedate">
                <el-date-picker
                  v-model="form.duedate"
                  type="date"
                  placeholder="选择日期"
                  format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD"
                  disabled
                />
              </el-form-item>
            </el-col>

            <el-col :span="10">
              <el-form-item label="贴现利息" prop="interestamount">
                <el-input v-model="form.interestamount" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="银行贴息" prop="interestendamount">
                <el-input v-model="form.interestendamount" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="贴现金额" prop="discountamount">
                <el-input v-model="form.discountamount" disabled />
              </el-form-item>
            </el-col>

            <el-col :span="10">
              <el-form-item label="账户" prop="account_id">
                <sk-select-group v-model="form.account_id" :list="accountList" />
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="入账日期" prop="usedate">
                <el-date-picker
                  v-model="form.usedate"
                  type="date"
                  placeholder="选择日期"
                  format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD"
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="handleremark">
                <el-input v-model="form.handleremark" type="textarea" rows="3"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </sk-tabs>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skSelectGroup from "@/components/skSelectGroup";
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
import XEUtils from "xe-utils";
export default {
  emits: ["success", "closed"],
  components: { skSelectGroup, skDicSelect, skAutoChoose },
  data() {
    return {
      accountList: [],
      form: {
        id: "",
        usedate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
        account_id: null,
      },
      rules: {
        account_id: { required: true, message: "请选择单据日期" },
        usedate: { required: true, message: "汇票编号必填" },
      },
      visible: false,
      isSaveing: false,
    };
  },

  mounted() {
    this.getAccount();
  },

  methods: {
    //显示
    open() {
      this.visible = true;
      return this;
    },
    getAccount() {
      this.$API.basedata.subject.list.get({ filter: [{ parent_id: 1002 }] }).then(res => {
        this.accountList = res.data;
      });
    },

    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async valid => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.finance.acceptance_rec.debtor.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },

    //表单注入数据
    setData(data) {
      Object.assign(this.form, this.$TOOL.removeNull(data));
    },
  },
};
</script>
<style></style>
